﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Fx.Utility
{
    public class Browser
    {
        public static string GetClientIp()
        {
            if (HttpContext.Current == null) return string.Empty;

            var ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ip == null)
                return HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
            var ipRange = ip.Split(',');
            var le = ipRange.Length - 1;
            if (le > -1)
            {
                ip = ipRange[le].Trim();
            }
            return ip;
        }
    }
}
